{include file="common/header" /}
<link href="__STATIC__/js/codemirror/codemirror.css" rel="stylesheet">
<link href="__STATIC__/js/codemirror/ambiance.css" rel="stylesheet">
<style>
    body {
        background-color: #ffffff;
    }
    .img-item {
        position: relative;
        width: 96px;
        height: 96px;
        border-radius: 6px;
        margin-bottom: 10px;
        margin-right: 10px;
    }
    .img-item img {
        border-radius: 6px;
        width: 100%;
        height: 100%;
    }
    .img-item i {
        font-size: 20px;
        position: absolute;
        top: -10px;
        right: -10px;
    }

</style>
<body>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>操作-编辑</legend>
</fieldset>
<div class="layui-form layuimini-form">
  	<form class="layui-form layui-form-pane" action="{:url('edit_all')}">
		<input type="hidden" name="fname" value={:input('param.fname')}>
		
		<div class="layui-form-item">
		    <label class="layui-form-label">css替换</label>
		    <div class="layui-input-inline" >
		      <input type="text" class="layui-input field-css" name="css" value="" autocomplete="off" placeholder="css/" >
		    </div>
		    <label class="layui-form-label">替换成</label>
		    <div class="layui-input-inline" >
		      <input type="text" class="layui-input field-upcss" name="upcss" value="" autocomplete="off" placeholder="__INDEXCSS__/" >
		    </div>
            <div class="layui-form-mid layui-text-em">__INDEXCSS__/</div>
		</div>
		
		<div class="layui-form-item">
		    <label class="layui-form-label">js替换</label>
		    <div class="layui-input-inline" >
		      <input type="text" class="layui-input field-js" name="js" value="" autocomplete="off" placeholder="js/" >
		    </div>
		    <label class="layui-form-label">替换成</label>
		    <div class="layui-input-inline" >
		      <input type="text" class="layui-input field-upjs" name="upjs" value="" autocomplete="off" placeholder="__INDEXJS__/" >
		    </div>
            <div class="layui-form-mid layui-text-em">__INDEXJS__/</div>
		</div>
		
		<div class="layui-form-item">
		    <label class="layui-form-label">image替换</label>
		    <div class="layui-input-inline" >
		      <input type="text" class="layui-input field-image" name="image" value="" autocomplete="off" placeholder="img/" >
		    </div>
		    <label class="layui-form-label">替换成</label>
		    <div class="layui-input-inline" >
		      <input type="text" class="layui-input field-upimage" name="upimage" value="" autocomplete="off" placeholder="__INDEXIMG__/" >
		    </div>
            <div class="layui-form-mid layui-text-em">__INDEXIMG__/</div>
		</div>
		
		  <div class="layui-form-item">
		    <div class="layui-input-block">
		      <button class="layui-btn" lay-submit lay-filter="submitForm">立即提交</button>
		      <a href="{:url('index',array('fname'=>input('param.fname')))}" class="layui-btn layui-btn-primary">返回</a>
		    </div>
		  </div>
	</form>

	<div class="layui-form-pane">
		<div class="layui-form-item layui-form-text">
		    <label class="layui-form-label" style="width:600px;">内容</label>
		    <div class="layui-input-block" >
		      
		      	<textarea id="content" name="content" style="display: none;" ></textarea>
				
		    </div>
	  	</div>
  	</div>

	<table class="layui-table">
      <colgroup>
        <col >
        <col >
        <col>
      </colgroup>
      <thead>
        <tr>
            <th>文件名称</th>
            <th>文件大小</th>
            <th>修改日期</th>
            <th>操作</th>
        </tr> 
      </thead>
      <tbody>
        {php}$i=1;{/php}
        {volist name="files" id="vo"}
        <tr id="{$i}">
            <td>
                {eq name="$vo['type']" value="dir"}
                    <a href="{:url('admin/template/index',array('fname'=>$vo['name']))}">
                        {$vo.name}[文件夹]
                    </a>
                {else/}
                    {$vo.name}
                {/eq}
            </td>
            <td>{$vo.filesize}</td>
            <td>{$vo.uptime}</td>
           
            <td>
                {if $vo.type == 'file' /}
                <a href="javascript:;" data-file_code="{$vo.file_code | raw}"  class="layui-btn layui-btn-xs showCode">查看代码</a>
                {/if}
            </td>
        </tr>
        {php}$i++;{/php}
        {/volist}
      </tbody>
    </table>


</div>
 
<script src="__STATIC__/js/codemirror/codemirror.js"></script>
<script src="__STATIC__/js/codemirror/mode/javascript/javascript.js"></script>

<script>
    // $(document).ready(function(){
    // 	var editor_one=CodeMirror.fromTextArea(
    // 		document.getElementById("content"),{
    // 			lineNumbers:true,matchBrackets:true,styleActiveLine:true,theme:"ambiance"
    // 		});
    // 	editor_one.setSize('height','400px');
    	
    // });
</script>

<script>

    layui.use(['form','iconPickerFa'], function () {
        var form = layui.form,
            iconPickerFa = layui.iconPickerFa,
            layer = layui.layer,
            $ = layui.$;

        $(".showCode").click(function(){
        	let file_code = $(this).attr("data-file_code");
        	$("#content").val(file_code);
        	$("#content").show();
        	var editor_one=CodeMirror.fromTextArea(
	    		document.getElementById("content"),{
	    			lineNumbers:true,matchBrackets:true,styleActiveLine:true,theme:"ambiance"
	    		});
	    	editor_one.setSize('height','400px');
        });
        //监听提交
        form.on('submit(submitForm)', function (data) {
            var index = layer.load(1, {
                shade: [0.3,'#000'] //0.1透明度的白色背景
            });
            var data = data.field;
            $.ajax({
                url:"{:url('template/edit_all')}",
                data:data,
                type:'post',
                dataType:'json',
                success:function(res){
                    console.log(res)
                    // return false
                    if(res.errcode != 1){
                        layer.msg(res.message,{icon: 2,time: 2000},function(){
                            layer.close(index);
                        })
                    }else{
                        layer.msg(res.message,{icon: 1,time: 1000},function () {
                            //window.location.href = "{:url('policy/list')}";
                            location.reload();
                        })
                    }
                    layer.close(index);
                },
                error : function(XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('网络失败，请刷新页面后重试!',{icon: 2,time: 2000})
                }
            });

            return false;
        });

    });
</script>
</body>
</html>